package util;

import java.util.Random;

public class Util {

	public static String toString(int arr[], String format) {
		boolean formatEmpty = format == null || format.length() == 0;
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0, size = arr.length; i < size; i++) {
			if (formatEmpty) {
				stringBuilder.append(arr[i]);
			} else {
				stringBuilder.append(String.format(format, arr[i]));
			}

			if ((i + 1) % 10 == 0) {
				stringBuilder.append('\n');
			} else {
				stringBuilder.append(',');
			}
		}

		return stringBuilder.toString();
	}

	public static int[] randomArray(int size, int bound) {
		int arr[] = new int[size];
		Random random = new Random();
		for (int i = 0; i < size; i++) {
			arr[i] = random.nextInt(bound);
		}
		return arr;
	}

	public static void swap(int arr[], int i, int j) {
		arr[i] = arr[i] ^ arr[j];
		arr[j] = arr[i] ^ arr[j];
		arr[i] = arr[i] ^ arr[j];
	}
}
